﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using WhatCatch.Core2.Model;

namespace WhatCatch.Core2
{
    public class DetailPageHandler: IPageHandle
    {
        CrawlerRobot _robot;
        public DetailPageHandler(CrawlerRobot robot)
        {
            _robot = robot;
        }


        public HandleTaskResponse Handle(CatchTask task)
        {
            _robot.CrawlerLog.Info($"处理(详情页)任务{task.Url}");

            //加载页面html
            var html = _robot.HttpLoader.GetHtml(task.Url);

            var analysierContext = new AnalyserContextRequest
            {
                Url = task.Url,
                Html = html,
                Task = task
            };

            //分析出内容
            var contentResponse = _robot.HtmlAnalyser.AnalyserContent(analysierContext);

            _robot.CrawlerLog.Info($"处理(详情页)任务结束 {task.Url}");

            return new HandleTaskResponse
            {
                Task = task,
                DetailContext = contentResponse
            };
        }
    }
}
